#ifndef __TCP_SERVER_TEST__
#define __TCP_SERVER_TEST__

#include <fcntl.h>
#include <iostream>
#include <netinet/in.h>
#include <signal.h>
#include <string.h>
#include <sys/epoll.h>
#include <sys/socket.h>
#include <unistd.h>

#define PORT 8997
#define MESSAGE_SIZE 5
#define EPOLL_EVENTS_SIZE 1024
namespace sdx
{
  class TcpServer
  {
  public:
    TcpServer();
    ~TcpServer();

  private:
    int socketFd = -1;
    int acceptFd = -1;
    int ret = -1;
    int flag = 1;
    char in_buff[MESSAGE_SIZE] = {0};
    char out_buff[22] = "received your message";
    struct sockaddr_in localAddr, remoteAddr;

  public:
    void createSocket();
    void bindIp();
    void listenData();
    void acceptMessage();
    int recvMessage();
    void sendMessage();
    void closeAccept();
    void closeSocket();
    int getAcceptFd();
    int getListenFd();
    int setFdnonblocking(int); //设置fd非阻塞，返回fd原flag;
    void addEpollInFd(int, int, bool);
    void EpollWorkInEt(epoll_event *, int, int);
    void EpollWorkInLt(epoll_event *, int, int);
  };
} // namespace sdx

#endif